/*
 * AdjacencyMatrix.cpp
 *
 *  Created on: 10/09/2014
 *      Author: Samuel
 */

#include "AdjacencyMatrix.h"

int AdjacencyMatrix::get(int i,int j){
	return matrix[i][j];
}

int AdjacencyMatrix::size(){
	return lenght;
}

AdjacencyMatrix::AdjacencyMatrix(std::string file){
	std::string line;
	std::fstream f(file);
	if (f.is_open()){
		int j;
		std::getline(f,line);
		std::cout << line << "\n";
		lenght = stoi(line,nullptr);
		allocArrays();
		int i = 0;
		while ( std::getline(f,line) ) {
			std::stringstream line2(line);
			std::string item;
			j = 0;
			while (line2 >> item) {
				matrix[i][j] = stoi (item,nullptr);
				j++;
			}
			i++;
		}
	}
}

 void AdjacencyMatrix::allocArrays(){
	matrix = new int*[lenght];
	for (int i = 0; i < lenght; i++) {
		matrix[i] = new int[lenght]; 
	}
}


